package cn.elwy.rcp.ui.table.model;

import java.io.Serializable;

import cn.elwy.rcp.ui.table.format.ColumnFormat;

public class ColumnInfo implements Comparable<ColumnInfo>, Serializable {

  private static final long serialVersionUID = 1L;

  public static String ORDER_FIELD = "order";

  private String id;
  private String name;
  // private int style;
  private String styleName;
  // private int alignment;
  private String alignmentName;
  private int width;
  private ColumnFormat columnFormat;
  private String formatPattern;
  private int order;
  private boolean canVisible = true;
  private boolean visible = true;
  private boolean canEditor = true;

  public String getId() {
    return id;
  }

  public void setId(String id) {
    this.id = id;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public boolean isCanEditor() {
    return canEditor;
  }

  public void setCanEditor(boolean canEditor) {
    this.canEditor = canEditor;
  }

  public int getWidth() {
    return width;
  }

  public void setWidth(int width) {
    this.width = width;
  }

  // public int getStyle() {
  // return style;
  // }
  //
  // public void setStyle(int style) {
  // this.style = style;
  // }

  public String getStyleName() {
    return styleName;
  }

  public void setStyleName(String styleName) {
    if (styleName == null) {
      this.styleName = "";
    } else {
      this.styleName = styleName.toUpperCase();
    }
  }

  // public int getAlignment() {
  // return alignment;
  // }
  //
  // public void setAlignment(int alignment) {
  // this.alignment = alignment;
  // }

  public String getAlignmentName() {
    return alignmentName;
  }

  public void setAlignmentName(String alignmentName) {
    if (alignmentName == null) {
      this.alignmentName = "";
    } else {
      this.alignmentName = alignmentName.toUpperCase();
    }
  }

  public ColumnFormat getColumnFormat() {
    return columnFormat;
  }

  public void setColumnFormat(ColumnFormat format) {
    this.columnFormat = format;
  }

  public String getFormatPattern() {
    return formatPattern;
  }

  public void setFormatPattern(String formatPattern) {
    this.formatPattern = formatPattern;
  }

  public void setOrder(int order) {
    this.order = order;
  }

  public int getOrder() {
    return order;
  }

  public boolean isCanVisible() {
    return canVisible;
  }

  public void setCanVisible(boolean canVisible) {
    this.canVisible = canVisible;
  }

  public boolean isVisible() {
    return visible;
  }

  public void setVisible(boolean visible) {
    this.visible = visible;
  }

  @Override
  public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + ((id == null) ? 0 : id.hashCode());
    return result;
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj)
      return true;
    if (obj == null)
      return false;
    if (getClass() != obj.getClass())
      return false;
    ColumnInfo other = (ColumnInfo) obj;
    if (id == null) {
      if (other.id != null)
        return false;
    } else if (!id.equals(other.id))
      return false;
    return true;
  }

  @Override
  public int compareTo(ColumnInfo column) {
    int otherOrder = column.getOrder();
    return order > otherOrder ? 1 : (order < otherOrder ? -1 : 0);
  }
}
